package com.uppfind.framework.dao.mybatis.generator.generator.config.converts;

import com.uppfind.framework.dao.mybatis.generator.generator.config.TypeConvert;
import com.uppfind.framework.dao.mybatis.generator.generator.config.rules.DBColumnType;

/**
 * MYSQL 数据库字段类型转换
 * Created by xuliugen on 2017/7/6.
 */
public class MySqlTypeConvert implements TypeConvert {

    public DBColumnType processTypeConvert(String fieldType) {
        String t = fieldType.toLowerCase();
        if (t.contains("char") || t.contains("text") || t.contains("varchar")) {
            return DBColumnType.MYSQL_STRING;
        } else if (t.contains("bigint")) {
            return DBColumnType.MYSQL_BIGINT;
        } else if (t.contains("int")) {
            return DBColumnType.MYSQL_INTEGER;
        } else if (t.contains("timestamp")) {
            return DBColumnType.MYSQL_TIMESTAMP;
        } else if (t.contains("date") || t.contains("time") || t.contains("year")) {
            return DBColumnType.MYSQL_DATE;
        } else if (t.contains("binary")) {
            return DBColumnType.MYSQL_BYTE_ARRAY;
        } else if (t.contains("float")) {
            return DBColumnType.MYSQL_FLOAT;
        } else if (t.contains("double")) {
            return DBColumnType.MYSQL_DOUBLE;
        }
        return DBColumnType.MYSQL_STRING;
    }

}
